home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / os2 / dialogs.c next >
Encoding:
C/C++ Source or Header  |  1998-04-15  |  16.5 KB  |  448 lines

  1. #ifdef INCRCar achBulÐ Àr RCSid[]="$Id: dialogs.c,v 1.1.1.2 1998/04/15 19:23:34 lhecking Exp $" ;
  2. #endif
  3.  
  4. /****************************************************************************
  5.  
  6.     PROGRAM: gnupmdrv
  7.     
  8.         Outboard PM driver for GNUPLOT 3.3
  9.  
  10.     MODULE:  dialogs.c  Dialog procedures for gnupmdrv 
  11.         
  12. ****************************************************************************/
  13.  
  14. /* PM driver for GNUPLOT */
  15.  
  16. /*[
  17.  * Copyright 1992, 1993, 1998   Roger Fearick
  18.  *
  19.  * Permission to use, copy, and distribute this software and its
  20.  * documentation for any purpose with or without fee is hereby granted,
  21.  * provided that the above copyright notice appear in all copies and
  22.  * that both that copyright notice and this permission notice appear
  23.  * in supporting documentation.
  24.  *
  25.  * Permission to modify the software is granted, but not the right to
  26.  * distribute the complete modified source code.  Modifications are to
  27.  * be distributed as patches to the released version.  Permission to
  28.  * distribute binaries produced by compiling modified sources is granted,
  29.  * provided you
  30.  *   1. distribute the corresponding source modifications from the
  31.  *    released version in the form of a patch file along with the binaries,
  32.  *   2. add special version identification to distinguish your version
  33.  *    in addition to the base release version number,
  34.  *   3. provide your name and address as the primary contact for the
  35.  *    support of your modified version, and
  36.  *   4. retain our contact information in regard to use of the base
  37.  *    software.
  38.  * Permission to distribute the released version of the source code along
  39.  * with corresponding source modifications in the form of a patch file is
  40.  * granted with same provisions 2 through 4 for binary distributions.
  41.  *
  42.  * This software is provided "as is" without express or implied warranty
  43.  * to the extent permitted by applicable law.
  44. ]*/
  45.  
  46. /*
  47.  * AUTHOR
  48.  * 
  49.  *   Gnuplot driver for OS/2:  Roger Fearick
  50.  * 
  51.  * Send your comments or suggestions to 
  52.  *  info-gnuplot@dartmouth.edu.
  53.  * This is a mailing list; to join it send a note to 
  54.  *  majordomo@dartmouth.edu.  
  55.  * Send bug reports to
  56.  *  bug-gnuplot@dartmouth.edu.
  57. **/
  58.  
  59. #define INCL_PM
  60. #define INCL_WIN
  61. #define INCL_DEV
  62. #define INCL_SPL
  63. #define INCL_SPLDOSPRINT
  64. #define INCL_WINDIALOGS
  65. #define INCL_WINBUTTONS
  66. #define INCL_WINSYS
  67. #define INCL_WINFRAMEMGR
  68. #define INCL_WINPOINTERS
  69. #define INCL_WINTRACKRECT
  70. #define INCL_WINENTRYFIELDS
  71. #define INCL_WINWINDOWMGR
  72. #include <os2.h>
  73. #include <math.h>
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <string.h>
  77. #include "gnupmdrv.h"
  78.  
  79. /* struct for printer capabilities */
  80.  
  81. static struct { 
  82.     long    lTech ;     // printer technology
  83.     long    lVer ;      // driver version
  84.     long    lWidth ;    // page width in pels
  85.     long    lHeight ;   // page height in pels
  86.     long    lWChars ;   // page width in chars    
  87.     long    lHChars ;   // page height in chars    
  88.     long    lHorRes ;   // horizontal resolution pels / metre
  89.     long    lVertRes ;  // vertical resolution pels / metre
  90.     } prCaps ;
  91.  
  92. ULONG GetPrinters( PPRQINFO3* pprq, ULONG *pcTot  ) ;
  93.  
  94.  
  95. MRESULT EXPENTRY QPrintDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  96. /*
  97. **  Query print area and printer setup
  98. */
  99.     {
  100.     static PQPRINT pqp = NULL ;
  101.     static SWP     swp ;    
  102.     static RECTL   rectlDef ;
  103.     TRACKINFO   ti ;
  104.     RECTL       rectlBox ;
  105.     HDC         hdc ;
  106.     ULONG       ulStyle ;
  107.     char        *psz ;
  108.  
  109.     switch ( usMsg ) {
  110.  
  111.         case WM_INITDLG :
  112.                                    
  113.             pqp = (PQPRINT) PVOIDFROMMP( mp2 ) ;
  114.             if( pqp->caps & QP_CAPS_FILE ) {
  115.                 ulStyle = WinQueryWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  116.                                                QWL_STYLE ) ;
  117.                 WinSetWindowULong( WinWindowFromID( hwnd, IDD_PRINTQNAME ),
  118.                                    QWL_STYLE, ulStyle ^ DT_HALFTONE  ) ;
  119.                 }
  120.             else {
  121.                 WinSendMsg( WinWindowFromID( hwnd, IDD_QPRNAME ),
  122.                             EM_SETREADONLY, (MPARAM)TRUE, 0L ) ;
  123.                 }
  124.             WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  125.                                 &rectlDef ) ;
  126.              
  127.         case WM_USER_SET_DATA :
  128.  
  129.             psz = *pqp->piPrinter->pszComment ? pqp->piPrinter->pszComment :
  130.                                         pqp->piPrinter->pszName ;
  131.             WinSetDlgItemText( hwnd, IDD_PRINTNAME, psz ) ;
  132.             WinSetDlgItemFloatF( hwnd, IDD_QPRXSIZE, 1, pqp->xsize ) ;
  133.             WinSetDlgItemFloatF( hwnd, IDD_QPRYSIZE, 1, pqp->ysize ) ;
  134.             WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  135.             WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  136.             WinQueryWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  137.                                &swp ) ;
  138.             {
  139.             int y = rectlDef.yTop ;
  140.             rectlBox = rectlDef ;
  141.             if( pqp->xsize < pqp->ysize )                    
  142.                 rectlBox.xRight = rectlDef.yTop * pqp->xsize/pqp->ysize ;
  143.             else {
  144.                 int x = rectlDef.yTop * pqp->ysize/pqp->xsize ;
  145.                 rectlBox.yTop = x ;
  146.                 rectlBox.xRight = y ;
  147.                 }
  148.             }
  149.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRBOX ),
  150.                              NULLHANDLE, 0, 0, (short) rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE ) ;
  151.             {
  152.             double ratio = 1.560 ;
  153.             double xs = rectlBox.xRight - rectlBox.xLeft ;
  154.             double ys = rectlBox.yTop - rectlBox.yBottom ;
  155.             if( ys > xs/ratio ) { /* reduce ys to fit */
  156.                  rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ; 
  157.                  }
  158.             else if( ys < xs/ratio ) { /* reduce xs to fit */
  159.                  rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
  160.                  }
  161.             }
  162.             rectlBox.xRight *= pqp->xfrac ;
  163.             rectlBox.yTop *= pqp->yfrac ;
  164.             WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  165.                              NULLHANDLE, 
  166.                              swp.x, swp.y, //+(short)(swp.cy*(1.0-pqp->yfrac)),
  167.                              (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  168.             break ;
  169.             
  170.         case WM_COMMAND :
  171.  
  172.             switch ( SHORT1FROMMP(mp1) ) {
  173.  
  174.                 case DID_OK:
  175.                     WinQueryDlgItemFloat( hwnd, IDD_QPRXFRAC, &pqp->xfrac ) ;
  176.                     WinQueryDlgItemFloat( hwnd, IDD_QPRYFRAC, &pqp->yfrac ) ;
  177.  
  178.                     if( pqp->caps & QP_CAPS_FILE ) {
  179.                         WinQueryDlgItemText( hwnd, IDD_QPRNAME, 32, pqp->szFilename ) ;
  180.                         }
  181.                     break ;
  182.  
  183.                 case IDD_QPRSETPR:   /* printer setup */
  184.                     if( SetPrinterMode( hwnd, pqp ) == 1 ) {
  185.                         if( (hdc = OpenPrinterDC( WinQueryAnchorBlock( hwnd ), 
  186.                                                   pqp, 
  187.                                                   OD_INFO, 
  188.                                                   NULL )) != DEV_ERROR ) {
  189.                             DevQueryCaps( hdc, CAPS_TECHNOLOGY, (long)sizeof(prCaps)/sizeof(long), (PLONG)&prCaps ) ;
  190.                             DevCloseDC( hdc ) ;
  191.                             pqp->xsize = (float)100.0* (float) prCaps.lWidth / (float) prCaps.lHorRes ; // in cm
  192.                             pqp->ysize = (float)100.0* (float) prCaps.lHeight / (float) prCaps.lVertRes ; // in cm
  193.                             WinSendMsg( hwnd, WM_USER_SET_DATA, 0L, 0L ) ;
  194.                             }
  195.                         }
  196.                     return 0L ;
  197.  
  198.                 case IDD_QPRTRACK :     /* track plot area */
  199.                     WinQueryWindowRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  200.                                         &rectlBox ) ;
  201.                     {
  202.                     double ratio = 1.560 ;
  203.                     double xs = rectlBox.xRight - rectlBox.xLeft ;
  204.                     double ys = rectlBox.yTop - rectlBox.yBottom ;
  205.                     if( ys > xs/ratio ) { /* reduce ys to fit */
  206.                         rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ; 
  207.                         }
  208.                     else if( ys < xs/ratio ) { /* reduce xs to fit */
  209.                         rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
  210.                         }
  211.                     }
  212.                     ti.cxBorder = ti.cyBorder = 2 ;
  213.                     ti.cxGrid = ti.cyGrid = 0 ;
  214.                     ti.cxKeyboard = ti.cyKeyboard = 2 ;
  215.                     ti.ptlMinTrackSize.x = ti.ptlMinTrackSize.y = 2 ;
  216.                     ti.rclBoundary = rectlBox ;
  217.                     ti.ptlMaxTrackSize.x = rectlBox.xRight ;
  218.                     ti.ptlMaxTrackSize.y = rectlBox.yTop ;
  219.                     ti.rclTrack.xRight = pqp->xfrac * rectlBox.xRight ;
  220.                     ti.rclTrack.yTop = pqp->yfrac*rectlBox.yTop ;
  221.                     ti.rclTrack.xLeft = 0 ;
  222.                     ti.rclTrack.yBottom = 0 ;//(1.0-pqp->yfrac) * rectlBox.yTop ;
  223.                     ti.fs = TF_RIGHT|TF_TOP|TF_STANDARD|TF_SETPOINTERPOS|TF_ALLINBOUNDARY ;
  224.                     WinSetPointer( HWND_DESKTOP, 
  225.                                    WinQuerySysPointer( HWND_DESKTOP, SPTR_SIZENWSE, FALSE ) ) ;
  226.                     WinTrackRect( WinWindowFromID( hwnd, IDD_QPRBOX ),
  227.                                   NULLHANDLE, 
  228.                                   &ti ) ;
  229.                     pqp->xfrac = (float)ti.rclTrack.xRight / (float)rectlBox.xRight ;
  230.                     pqp->yfrac = ((float)(ti.rclTrack.yTop-ti.rclTrack.yBottom) / (float)rectlBox.yTop) ;
  231.                     rectlBox.yTop = ti.rclTrack.yTop - ti.rclTrack.yBottom ;
  232.                     rectlBox.xRight = ti.rclTrack.xRight ;
  233.                     {
  234.                     double ratio = 1.560 ;
  235.                     double xs = rectlBox.xRight - rectlBox.xLeft ;
  236.                     double ys = rectlBox.yTop - rectlBox.yBottom ;
  237.                     if( ys > xs/ratio ) { /* reduce ys to fit */
  238.                         rectlBox.yTop = rectlBox.yBottom + (int)(xs/ratio) ; 
  239.                         }
  240.                     else if( ys < xs/ratio ) { /* reduce xs to fit */
  241.                         rectlBox.xRight = rectlBox.xLeft + (int)(ys*ratio) ;
  242.                         }
  243.                     }
  244.                     WinSetWindowPos( WinWindowFromID( hwnd, IDD_QPRFRAME ),
  245.                                      NULLHANDLE, 
  246.                                      swp.x, swp.y,//+(short)(swp.cy*(1.0-pqp->yfrac)),
  247.                                      (short)rectlBox.xRight, (short)rectlBox.yTop, SWP_SIZE|SWP_MOVE ) ;
  248.                     WinSetDlgItemFloat( hwnd, IDD_QPRXFRAC, pqp->xfrac ) ;
  249.                     WinSetDlgItemFloat( hwnd, IDD_QPRYFRAC, pqp->yfrac ) ;
  250.                     return 0L ;
  251.                     
  252.                 default:
  253.                     break ;
  254.                 }
  255.                 
  256.          default:
  257.             break ;
  258.             }
  259.         /* fall through to the default control processing */
  260.  
  261.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  262.     }
  263.  
  264. MRESULT EXPENTRY QPrintersDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  265. /*
  266. **  Query printers and allow selection
  267. */
  268.     {
  269.     static HWND hwndLB ;
  270.     static PPRQINFO3 pprq=NULL ;
  271.     static ULONG cPrinters ;
  272.     static USHORT usItem ;
  273.     static char *szPrinterName ;
  274.     int i, iSelect ;
  275.     char *psz ;
  276.  
  277.     switch ( usMsg ) {
  278.  
  279.         case WM_INITDLG :
  280.  
  281.             szPrinterName = (char*) PVOIDFROMMP( mp2 ) ;
  282.             iSelect = 0 ;
  283.             GetPrinters( &pprq, &cPrinters ) ;
  284.             hwndLB = WinWindowFromID( hwnd, IDD_QPRSLIST ) ;
  285.             for( i=0; i<cPrinters;i++ ) {
  286.                 psz = *pprq[i].pszComment ? pprq[i].pszComment :
  287.                                             pprq[i].pszName ;
  288.                 WinSendMsg( hwndLB,
  289.                             LM_INSERTITEM,
  290.                             (MPARAM)LIT_END,
  291.                             MPFROMP(psz) ) ;
  292.                 if( strcmp( pprq[i].pszName, szPrinterName ) == 0 )
  293.                     iSelect = i ;
  294.                 } 
  295.                 
  296.             WinSendMsg( hwndLB,
  297.                         LM_SELECTITEM,
  298.                         MPFROMSHORT( iSelect ),
  299.                         (MPARAM)TRUE ) ;
  300.        
  301.             break ;
  302.  
  303.         case WM_COMMAND :
  304.  
  305.             switch ( SHORT1FROMMP(mp1) ) {
  306.  
  307.                 case DID_OK:
  308.                     strcpy( szPrinterName, pprq[usItem].pszName ) ;
  309.                 case DID_CANCEL:
  310.                     free( pprq ) ;
  311.                     pprq = NULL;
  312.                     break ;
  313.                 }
  314.             break ;
  315.  
  316.         case WM_CONTROL:
  317.         
  318.             if( SHORT1FROMMP( mp1 ) == IDD_QPRSLIST ) {
  319.                 if( SHORT2FROMMP( mp1 ) == LN_SELECT  ) {
  320.                     usItem = (ULONG)WinSendMsg( hwndLB,
  321.                                 LM_QUERYSELECTION,
  322.                                 0L,
  323.                                 0L ) ;
  324.                     }
  325.                 }
  326.  
  327.         default:
  328.             break ;
  329.         }
  330.         /* fall through to the default control processing */
  331.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  332.     }
  333.     
  334. ULONG GetPrinters( PPRQINFO3 *pprq, ULONG *pcTot  )
  335. /*
  336. ** get a list of printers
  337. */
  338.     {
  339.     ULONG rc ;
  340.     ULONG cQueues, cbData ;
  341.     
  342.     rc = SplEnumQueue( NULL, 3, NULL, 0, &cQueues, pcTot, &cbData, NULL ) ;
  343.    
  344.     if( *pprq != NULL ) {
  345.         free( *pprq ) ;
  346.         *pprq = NULL ;
  347.         }
  348.     if( *pcTot == 0 ) { /* no printers */
  349.         return 0 ;
  350.         }
  351.     *pprq = malloc( cbData ) ;
  352.     rc = SplEnumQueue( NULL,
  353.                        3,
  354.                        *pprq,
  355.                        cbData,
  356.                        &cQueues,
  357.                        pcTot,
  358.                        &cbData,
  359.                        NULL ) ;
  360.     return *pcTot ;
  361.     }
  362.  
  363. MRESULT EXPENTRY PauseMsgDlgProc ( HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2 )
  364. /*
  365. **  Pause message dialog box proc
  366. */
  367.     {
  368.     static PPAUSEDATA ppdata = NULL ;
  369.     char *pszText ;
  370.     switch ( usMsg ) {
  371.  
  372.         case WM_INITDLG :
  373.                 /* set the position so user can move out the way, and
  374.                    have it come back there next time */
  375.             ppdata = (PPAUSEDATA) PVOIDFROMMP( mp2 ) ;
  376.             if( ppdata->pswp != NULL ) 
  377.                 WinSetWindowPos( hwnd, HWND_TOP, ppdata->pswp->x, ppdata->pswp->y,
  378.                                  0, 0, SWP_MOVE ) ; 
  379.             pszText = ppdata->pszMessage ;
  380.             while(*pszText==' ') ++pszText ;
  381.             WinSetDlgItemText( hwnd, IDD_PAUSETEXT, pszText ) ;
  382.             break ;
  383.  
  384.         case WM_COMMAND :
  385.             switch ( SHORT1FROMMP(mp1) ) {
  386.                 case DID_OK:
  387.                 case DID_CANCEL:
  388.                     WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
  389.                                 WM_PAUSEEND, 
  390.                                 SHORT1FROMMP(mp1)==DID_OK?(MPARAM)1L:0L, 
  391.                                 0L ) ;
  392.                     if( ppdata->pswp == NULL ) ppdata->pswp = (PSWP)malloc( sizeof(SWP) ) ;
  393.                     WinQueryWindowPos( hwnd, ppdata->pswp ) ;
  394.                     WinDismissDlg( hwnd, 0 ) ; 
  395.                     break ;
  396.                 case IDM_PRINT:
  397.                     WinPostMsg( WinQueryWindow( hwnd, QW_OWNER ),
  398.                                 WM_COMMAND, 
  399.                                 MPFROMSHORT(IDM_PRINT), 
  400.                                 0L ) ;
  401.                     return 0 ;
  402.                 default:
  403.                     break ;
  404.                 }
  405.         default:
  406.             break ;
  407.         }
  408.         /* fall through to the default control processing */
  409.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  410.     }
  411.     
  412. void WinSetDlgItemFloatF( HWND hwnd, USHORT usID, int nDec, float flValue )
  413. /*
  414. */
  415.     {
  416.     char achBuffer [ 34 ], *szCvt ; // default string field size ...
  417.     int  iDec ;
  418.     int  iSign ;
  419.     char fmt[32] ;
  420.     sprintf( fmt, "%%12.%df", nDec ) ;
  421.     sprintf( achBuffer, fmt, flValue ) ;
  422.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  423.     }
  424.  
  425. void WinSetDlgItemFloat( HWND hwnd, USHORT usID, float flValue )
  426. /*
  427. */
  428.     {
  429.     char achBuffer [ 34 ] ; // default string field size ...
  430.     char fmt[10] ;
  431.     sprintf( fmt, "%%12.%df", 4 ) ;
  432.     sprintf( achBuffer, fmt, flValue ) ;
  433.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  434.     WinSetDlgItemText( hwnd, usID, achBuffer ) ;
  435.     }
  436.  
  437. void WinQueryDlgItemFloat( HWND hwnd, USHORT usID, float *pflValue )
  438. /*
  439. */
  440.     {
  441.     char achBuffer [ 34 ] ; // default string field size ...
  442.     ULONG ulTemp ;
  443.     
  444.     WinQueryDlgItemText( hwnd, usID, 34, achBuffer ) ;
  445.     *pflValue = (float) atof( achBuffer ) ;
  446.     }
  447.  
  448.